//
//  CardDetailHeadView.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2019/1/2.
//  Copyright © 2019年 DUONIU_MAC. All rights reserved.
//

import UIKit

class CardDetailHeadView: UIView {
    
    var cardName : String!{ //卡名
        didSet{
            cardLabel.text = cardName
        }
    }
    
    var percent : String!{ //匹配度
        didSet{
            meetLabel.text = suitability + "：" + percent
            meetLabel.attributedText = meetLabel.text?.setTextFont(color: UIColor.red, fontSize: RATIO(maxNum: 20), ranStr: percent)
        }
    }
    
    fileprivate let cardLabel = UILabel() //信用卡
    fileprivate let meetLabel = UILabel() //匹配度
    let meetButton = UIButton() //重新匹配
    

    init() {
        super.init(frame: .zero)
        
        let whiteView = UIView()
        whiteView.backgroundColor = UIColor.white
        whiteView.layer.cornerRadius = RATIO(maxNum: 5)
        whiteView.layer.masksToBounds = true
        self.addSubview(whiteView)
        
        let titleImageView = UIImageView()
        titleImageView.image = UIImage.init(named: "xykyx")
        self.addSubview(titleImageView)
        
        let titleLabel = UILabel()
        titleLabel.text = optimizationCarForyou
        titleLabel.font = UIFont.systemFont(ofSize: 16)
        titleImageView.addSubview(titleLabel)
        
        cardLabel.textColor = UIColor.red
        cardLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        cardLabel.numberOfLines = 2
        whiteView.addSubview(cardLabel)
        
        meetLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        whiteView.addSubview(meetLabel)
        
        meetButton.backgroundColor = UIColor.red
        meetButton.setTitle(recalculate, for: .normal)
        meetButton.titleLabel?.font = UIFont.systemFont(ofSize: RATIO(maxNum: 14))
        meetButton.layer.cornerRadius = RATIO_H(maxNum: 12)
        meetButton.layer.masksToBounds = true
        whiteView.addSubview(meetButton)
        
        let cardImageView = UIImageView()
        cardImageView.image = UIImage.init(named: "creditcard")
        whiteView.addSubview(cardImageView)
        
        whiteView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(RATIO_H(maxNum: 10))
            make.left.equalToSuperview().offset(RATIO(maxNum: 10))
            make.right.equalToSuperview().offset(RATIO(maxNum: -10))
            make.bottom.equalToSuperview()
        }
        
        titleImageView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(RATIO_H(maxNum: 40))
            make.left.equalToSuperview().offset(RATIO(maxNum: 4))
            make.height.equalTo(RATIO_H(maxNum: 30))
            make.right.equalTo(self.snp.centerX).offset(RATIO(maxNum: -10))
        }
        
        titleLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(RATIO(maxNum: 26))
            make.bottom.equalTo(titleImageView)
            make.height.greaterThanOrEqualTo(10)
            make.right.equalTo(titleImageView)
        }
        
        cardLabel.snp.makeConstraints { (make) in
            make.top.equalTo(titleLabel.snp.bottom).offset(RATIO_H(maxNum: 10))
            make.right.equalTo(titleLabel)
            make.height.greaterThanOrEqualTo(10)
            make.left.equalToSuperview().offset(RATIO(maxNum: 20))
        }
        
        meetLabel.snp.makeConstraints { (make) in
            make.top.equalTo(cardLabel.snp.bottom).offset(RATIO_H(maxNum: 10))
            make.left.right.equalTo(cardLabel)
            make.height.greaterThanOrEqualTo(10)
            
        }
        
        meetButton.snp.makeConstraints { (make) in
            make.top.equalTo(meetLabel.snp.bottom).offset(RATIO_H(maxNum: 10))
            make.left.equalTo(meetLabel)
            make.width.equalTo(RATIO(maxNum: 80))
            make.height.equalTo(RATIO_H(maxNum: 24))
        }
        
        cardImageView.snp.makeConstraints { (make) in
            make.top.equalTo(titleImageView)
            make.bottom.right.equalToSuperview()
            make.left.equalToSuperview().offset(ScreenW/2 + RATIO(maxNum: 10))
            
        }
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
